<?php
namespace Admin\Controller;

use Admin\Controller\CommonController;
use Common\Model\AdminModel;
/**
 * 管理员控制器
 */
class IndexController extends CommonController
{
    /**
     * index方法
     */
    public function index()
    {
        $this->display();
    }

    /**
     * 微信管理左侧导航
     */
    public function wleft()
    {
        $this->display();
    }

    /**
     * app管理左侧导航
     */
    public function aleft()
    {
        $this->display();
    }


    /**
     * phone管理左侧导航
     */
    public function pleft()
    {
        $this->display();
    }

    /**
     * 后台首页主题默认欢迎页面
     */
    public function welcome()
    {
        $key = sprintf('%s_%s', C('COOKIEVALIDATIONKEY'), 'aid');
        $userCookie = cookie($key) ? cookie($key) : '';
        $id = $userCookie[0];
        $userModel = new AdminModel();
        $userData = $userModel->getUserById($id);

        $todayTime = date("Y-m-d H:i:s",time());
        $yesterdayTime = date('Y-m-d',strtotime('-1 day'));
        $lastDayTime = date('Y-m-d',strtotime('-2 day'));
        $lastWeekTime = date('Y-m-d',strtotime('-7 day'));
        $infoModel = M('info_content');
        $infoCountTody = $infoModel
            ->where("create_time >= '{$yesterdayTime}' and create_time < '{$todayTime}' ")
            ->field("count(*) as count")
            ->find();
        $infoCountYesterDay = $infoModel
            ->where("create_time >= '{$lastDayTime}' and create_time < '{$yesterdayTime}' ")
            ->field("count(*) as count")
            ->find();
        $infoCountLastWeekCount = $infoModel
            ->where("create_time >= '{$lastWeekTime}' and create_time < '{$todayTime}' ")
            ->field("count(*) as count")
            ->find();

        $newsModel = M('news_content');
        $newsCountTody = $newsModel
            ->where("create_time >= '{$yesterdayTime}' and create_time < '{$todayTime}' ")
            ->field("count(*) as count")
            ->find();
        $newsCountYesterDay = $newsModel
            ->where("create_time >= '{$lastDayTime}' and create_time < '{$yesterdayTime}' ")
            ->field("count(*) as count")
            ->find();
        $newsCountLastWeekCount = $newsModel
            ->where("create_time >= '{$lastWeekTime}' and create_time < '{$todayTime}' ")
            ->field("count(*) as count")
            ->find();


        $newsModel = M('news_content');
        $newsCountTody = $newsModel
            ->where("create_time >= '{$yesterdayTime}' and create_time < '{$todayTime}' ")
            ->field("count(*) as count")
            ->find();
        $newsCountYesterDay = $newsModel
            ->where("create_time >= '{$lastDayTime}' and create_time < '{$yesterdayTime}' ")
            ->field("count(*) as count")
            ->find();
        $newsCountLastWeekCount = $newsModel
            ->where("create_time >= '{$lastWeekTime}' and create_time < '{$todayTime}' ")
            ->field("count(*) as count")
            ->find();

        $userModel = M('user');
        $userCountTody = $userModel
            ->where("create_time >= '{$yesterdayTime}' and create_time < '{$todayTime}' ")
            ->field("count(*) as count")
            ->find();
        $userCountYesterDay = $userModel
            ->where("create_time >= '{$lastDayTime}' and create_time < '{$yesterdayTime}' ")
            ->field("count(*) as count")
            ->find();
        $userCountLastWeekCount = $userModel
            ->where("create_time >= '{$lastWeekTime}' and create_time < '{$todayTime}' ")
            ->field("count(*) as count")
            ->find();

        $server = array(
            'DOCUMENT_ROOT' => $_SERVER['DOCUMENT_ROOT'],
            'WEB_SERVER' => $_SERVER["SERVER_SOFTWARE"],
            'HTTP_USER_AGENT' => $_SERVER['HTTP_USER_AGENT'],
            'HTTP_ACCEPT_ENCODING' => $_SERVER['HTTP_ACCEPT_ENCODING'],
            'PHP_VERSION' => PHP_VERSION,
            'PHP_SYSTEM'  => PHP_OS,
            'CURL_GETINFO' => !function_exists("curl_getinfo") ? '不支持(采集功能)' : '支持(采集功能)',
        );


        $this->assign('userData',$userData)
            ->assign('infoCountTody',$infoCountTody['count'])
            ->assign('infoCountYesterDay',$infoCountYesterDay['count'])
            ->assign('infoCountLastWeekCount',$infoCountLastWeekCount['count'])
            ->assign('newsCountTody',$newsCountTody['count'])
            ->assign('newsCountYesterDay',$newsCountYesterDay['count'])
            ->assign('newsCountLastWeekCount',$newsCountLastWeekCount['count'])
            ->assign('userCountTody',$userCountTody['count'])
            ->assign('userCountYesterDay',$userCountYesterDay['count'])
            ->assign('userCountLastWeekCount',$userCountLastWeekCount['count'])
            ->assign('server',$server)
        ;
        $this->display();
    }



    /**
     * 左侧
     */
    public function left()
    {
        $this->display();
    }

    /**
     * 后台页脚
     */
    public function footer()
    {
        $this->display();
    }


}
 

